<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>新增用户</title>
    <link rel="stylesheet" th:href="@{~/component/pear/css/pear.css}" media="all">
    <link rel="stylesheet" th:href="@{~/common/css/common.css}" media="all">
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">所属部门</label>
                    <div class="layui-input-block">
                    	<ul id="deptTree" class="dtree" data-id="0"></ul>
                        <!-- <input id="deptId" type="text" style="display:none" name="deptId" class="layui-input">
                        <input id="deptName" type="text" readonly="readonly"  autocomplete="off" placeholder="请选择部门" class="layui-input"> -->
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">用户角色</label>
                    <div  class="layui-input-block ">
                        <select id="roleIds" name="roleIds"  xm-select>
                        	<option value='' disabled style='display:none;'>请选择角色</option>
	            			<!-- <option value="1" >超级管理员</option>
	            			<option value="2" >管理员</option>
	            			<option value="3">普通用户</option>  -->
	            		</select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">用户账号</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" lay-verify="required" autocomplete="off" placeholder="请输入用户账号" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">用户名称</label>
                    <div class="layui-input-block">
                        <input type="text"  name="nickname" lay-verify="required" autocomplete="off" placeholder="请输入用户名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">用户电话</label>
                    <div class="layui-input-block">
                        <input type="text"  name="phone" lay-verify="phone" autocomplete="off" placeholder="请输入用户电话" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">用户性别</label>
                    <div class="layui-input-block">
                        <input type="radio" name="sex" value="1" title="男" checked>
                        <input type="radio" name="sex" value="0" title="女">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">账号状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="status" value="1" title="正常" checked>
                        <input type="radio" name="status" value="0" title="禁用">
                    </div>
                </div>
                
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="user-save">
                <i class="layui-icon layui-icon-release"></i> 确认新增
            </button>
            <button type="button" id="close" class="pear-btn pear-btn-danger pear-btn-sm" >
                <i class="layui-icon layui-icon-close"></i> 取消
            </button>
        </div>
    </div>
</form>
<script th:src="@{~/component/layui/layui.js}" charset="utf-8"></script>
<script th:src="@{~/component/pear/pear.js}" charset="utf-8"></script>
<script>
layui.use(['form','jquery','dtree','select'],function(){
    let form = layui.form
    	,dtree = layui.dtree
    	,select = layui.select;
    let $ = layui.jquery;
    
    form.on('submit(user-save)', function(data){
    	
        $.ajax({
            url:'/user/insert',
            data:JSON.stringify(data.field),
            dataType:'json',
            contentType:'application/json',
            type:'post',
            success:function(result){
                if(result.code == 0){
                    layer.msg(result.msg,{icon:1,time:1000},function(){
                        parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                        parent.layui.table.reload("user-table");
                    });
                }else{
                    layer.msg(result.msg,{icon:2,time:3000});
                }
            }
        })
        return false;
    });
    
    /* 渲染部门树形选择框 */
    dtree.render({
        elem: "#deptTree",
        initLevel: "1",
        method: 'get',
        selectTips: "请选择部门",
        ficon: ["1", "-1"],
        icon:"2",
        selectInputName: {
          nodeId: "deptId",
          context: "deptName"
        },
        dataStyle: "layuiStyle",
        url: "/dept/selectDeptTree",
        response:{message:"msg",statusCode:0},
        select: true
    });
    
    /** 渲染下拉框多选框**/
    $.get("/role/selectList",{"status":"1"},function(result){
    	if(result.code == 0){
    		for(var i = 0; i < result.data.length; i++){
	    		$('#roleIds').append(new Option(result.data[i].name,result.data[i].id));
    		}
    		select.render('roleIds');
    	}else{
    		layer.msg(result.msg);
    	}
    });
    
    $("#close").click(function(){
    	parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
    });
})

	


</script>
<script>
</script>
</body>
</html>